#include "test_student.h"
#include <assert.h>

using namespace CppUnit;

// method to test the constructor
void StudentTestCase::testConstructor() {  // Note 4
	// create a student object
	Student stu("Tan Meng Chee", "94-1111B-13");

	// check that the object is constructed correctly - Note 5
	string student_name = stu.getStudentName();
	assert(student_name == "Tan Meng Chee");
	string student_number = stu.getStudentNumber();
	assert(student_number == "94-1111B-13");
}

// method to test the assigning and retrieval of grades
void StudentTestCase::testAssignAndRetrieveGrades() {
	// create a student
	Student stu("Jimmy", "946302B");

	// assign a few grades to this student
	stu.assignGrade("cs2102", 60);
	stu.assignGrade("cs2103", 70);
	stu.assignGrade("cs3214s", 80);

	// verify that the assignment is correct - Note 6
	assertEquals(60, stu.getGrade("cs2102"));
	assertEquals(70, stu.getGrade("cs2103"));
					
	// attempt to retrieve a course that
	// does not exist
	assertEquals(-1, stu.getGrade("cs21002"));
}

// method to create a suite of
// tests - Note 7
Test *StudentTestCase::suite () {
	TestSuite *testSuite = new TestSuite ("StudentTestCase");
							
	// add the tests
	testSuite->addTest(new TestCaller  
		("testConstructor", &StudentTestCase::testConstructor));
	testSuite->addTest(new TestCaller 
		("testAssignAndRetrieveGrades", &StudentTestCase::testAssignAndRetrieveGrades));
	return testSuite;
}

int main (int argc, char* argv[]) {
	if (argc != 2) {
		cout << "usage: tester name_of_class_being_test" << endl;
	    exit(1);
	}

	TestRunner runner;
	runner.addTest(argv[1], StudentTestCase::suite());
	runner.run(argc, argv);
			    
	return 0;
}
